define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/appoints/index' + location.search,
                    add_url: 'user/appoints/add',
                 //   edit_url: 'user/appoints/edit',
                    //del_url: 'user/appoints/del',
                    multi_url: 'user/appoints/multi',
                    import_url: 'user/appoints/import',
                    table: 'user_appoints',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cards.rights_title', title: __('权益'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'tag_text',title: __('服务类型'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'business.business_name', title: __('企业名称'), operate: 'LIKE'},
                        //{field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'hospital.hospital_name', title: __('Hospital.hospital_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'rights_title', title: __('Rights_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'rights_memo', title: __('Rights_memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'card_id', title: __('Card_id')},
                        // {field: 'medical_info_id', title: __('Medical_info_id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'card_no', title: __('Card_no')},
                        {field: 'appoint_mobile', title: __('Mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('状态') ,searchList: {"0":__('预约中'),"1":__('预约成功'),"-1":__('预约取消')}, formatter: Table.api.formatter.normal},
                        {field: 'is_send', title: __('Is_send'), searchList: {"0":__('Is_send 0'),"1":__('Is_send 1'),"2":__('Is_send 2')}, formatter: Table.api.formatter.normal},
                        {field: 'is_success', title: __('预约成功短信发送状态') ,searchList: {"0":__('Is_send 0'),"1":__('Is_send 1'),"2":__('Is_send 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                        // {field: 'cards.rights_nums', title: __('Cards.rights_nums')},
                        // {field: 'cards.can_uses', title: __('Cards.can_uses')},
                        // {field: 'cards.used_nums', title: __('Cards.used_nums')},
                        // {field: 'info.medical_username', title: __('Info.medical_username'), operate: 'LIKE'},
                        // {field: 'info.medical_gender', title: __('Info.medical_gender')},
                        // {field: 'info.medical_cardno', title: __('Info.medical_cardno'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate ,buttons: [{
                                name: 'send',
                                text: '',
                                title: '详情',
                                icon: 'fa fa-eye',
                                classname: 'btn btn-xs btn-warning btn-dialog chakan',
                                url: 'user/appoints/detail'
                            },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
